package com.jnshu.tools.resultUtils;

/**
 * @author pipiretrak
 * @date 2019/7/31 - 10:57
 */
public enum ResultEnum {
    /**
     * 公共约定
     */
    SUCCESS(200,"请求成功"),
    FAILURE(400,"请求失败"),
    NOTHINGNESS(401,"请求用户或资源不存在"),
    PHONE_ERROR(504,"手机号码错误"),
    EMAIL_ERROR(504,"邮箱地址错误"),
    EMAIL_BINDING(508,"请勿板顶相同邮箱"),
    CODE_ERROR(509,"验证码错误"),
    TIME_ERROR(402,"延迟时间不能是过去的时间"),

    /**
     * 消息管理code码
     */
    Message_Status_Fail(500,"公告未下架且ID为空"),

    /**
     * 后台管理code码
     */
    SAME_NAME(601,"该用户名已经被使用,或账户为空"),
    ERROR_NULL_MANAGE(602,"更新账户为空"),
    ERROR_ADD(603,"已存在新增失败"),
    ERROR_PASSWORD(604,"登录密码错误")
    ;

    private int code;
    private String message;

    ResultEnum(int code,String message){
        this.code = code;
        this.message = message;
    }

    /**
     * 获取code对应的message
     * @param code
     * @return
     */
    public static String getName(int code) {
        for (ResultEnum c : ResultEnum.values()) {
            if (c.getCode() == code) {
                return c.message;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
